﻿using Microsoft.EntityFrameworkCore;
using Naruto.Repository;
using Naruto.TaskManagement.Entitys;
using Naruto.TaskManagement.Entitys.Models;
using Naruto.TaskManagement.IRepository;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Naruto.TaskManagement.Repository
{
    public class TaskRecordImageRepository : ITaskRecordImageRepository
    {
        private readonly IRepository<TaskManagementContext> repository;


        public TaskRecordImageRepository(IRepository<TaskManagementContext> _repository)
        {
            repository = _repository;
        }

        public async Task Add(List<TaskRecordImage> list)
        {
            await repository.Command<TaskRecordImage>().BulkAddAsync(list);
        }

        /// <summary>
        /// 根据记录id 删除
        /// </summary>
        /// <param name="taskRecordId"></param>
        /// <returns></returns>
        public async Task Delete(string taskRecordId)
        {
            await repository.Command<TaskRecordImage>().BulkDeleteAsync(a => a.TaskRecordId == taskRecordId);
        }

        /// <summary>
        /// 获取图片
        /// </summary>
        /// <param name="taskRecordId"></param>
        /// <returns></returns>
        public async Task<List<string>> GetImages(string taskRecordId)
        {
            var taskRecordImageQueryable = await repository.QueryAsync<TaskRecordImage>();
            return await taskRecordImageQueryable.Where(a => a.TaskRecordId == taskRecordId)
                  .AsNoTracking()
                  .Select(a => a.ImageUrl)
                  .ToListAsync();
        }
    }
}
